<?php

  function validateFormFieldMessage( $fieldName, $fieldValue )
  {
      if ( empty( $fieldValue ) )
	  {
	      echo "Введите пожалуйста " . $fieldName . "\n";
	  }
  }

  $name = isset($_POST['name']) ? $_POST['name'] : "";
  $email = isset($_POST['email']) ? $_POST['email'] : "";
  $phone = isset($_POST['phone']) ? $_POST['phone'] : "";
  $message = isset($_POST['message']) ? $_POST['message'] : "";
	
  validateFormFieldMessage( 'Ваше имя', $name );
  validateFormFieldMessage( 'Ваш email', $email );
  validateFormFieldMessage( 'Ваш телефон', $phone ); 
  
  $filledFields = ( $name != "" && $email != "" && $phone != "");
  if ( $filledFields )
  {
      $subject = 'Message from site';
      $message = "Member's email: " . $email . "\r\nMember's phone: " . $phone . "\r\nMember's name: " . $name . "\r\nMember's message:\r\n" . $message;
      $header = "From: test@test.test";
      mail( $email, $subject, $message, $header);
	  echo "Данные формы были отправлены. Спасибо.";
  }